/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGEKNIFEPRO_IMAGEKNIFE_NODE_CUSTOM_H
#define IMAGEKNIFEPRO_IMAGEKNIFE_NODE_CUSTOM_H

#include <database/udmf/udmf.h>
#include "imageknife_node_image.h"
#include "render/imageknife_render.h"
namespace ImageKnifePro {
class ImageKnifeNodeCustom : public ImageKnifeNodeImage, public ImageKnifeRender {
public:
    explicit ImageKnifeNodeCustom(std::shared_ptr<ImageKnifeOption> option);

    ~ImageKnifeNodeCustom() override;

    void Draggable(bool draggable) override;

    void FitImage(int fitEnum) override;

    void SetColorFilter(std::shared_ptr<ImageKnifeColorFilter> colorFilter) override;

    void RemoveColorFilter() override;

    void OnDerivedNodeEvent(ArkUI_NodeEvent *event) override;

    void UpdateDerivedNodeEvent(std::shared_ptr<ImageKnifeOption> option) override;

    void RemoveDisplayedImage() override;

    void Execute() override;
private:
    struct DragData {
        OH_UdmfRecord *record = nullptr;
        OH_UdsPixelMap *udsPixelmap = nullptr;
        OH_UdmfData *data = nullptr;
    };
    DragData dragData_;

    uint32_t width_ = 0;
    uint32_t height_ = 0;

    OH_PixelmapNative *renderPixelmap_ = nullptr;
    std::shared_ptr<ImageDataCacheInternal> dataCache_ = nullptr;

    // ImageFit, ArkUI_ObjectFit 枚举入参类型
    int imageFit_ = ARKUI_OBJECT_FIT_CONTAIN;
    std::shared_ptr<ImageKnifeColorFilter> colorFilter_ = nullptr;
    std::function<void(EventImage image)> onImageComplete_ = nullptr;

    bool needClear_ = false;
    bool registeredDragEvents_ = false;

    Image_Size GetComponentSize() override;

    bool DrawingFrame(std::shared_ptr<ImageDataCacheInternal> data, int frameCount = 0) override;

    void SetContentTransition(ContentTransitionType effectType) override;
    void RefreshImage() override;
    void RefreshDrawing() override;

    void SetResizeableOption(std::shared_ptr<ResizableOption> resizeable) override;
    void RemoveResizeableOption() override;

    void RegisterDragEvents();
    void UnRegisterDragEvents();
    void OnDragStart(ArkUI_NodeEvent *event);
    void OnDragEnd(ArkUI_NodeEvent *event);

    void OnDraw(ArkUI_NodeCustomEvent *event);
    void OnMeasure(ArkUI_NodeCustomEvent *event);

    static void OnCustomNodeEvent(ArkUI_NodeCustomEvent *event);
};
}
#endif //IMAGEKNIFEPRO_IMAGEKNIFE_NODE_CUSTOM_H
